package com.qianda.qdminiapp.security;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.math.BigDecimal;
import java.util.Collection;

/**
 * @ClassName SecurityUser
 * @Author cw
 * @Date 2019/8/6 17:01
 * @Version 1.0
 */
public class SecurityUser implements UserDetails {

    private static final long serialVersionUID = 1L;

    private final long id;
    private String phone;
    private final UserDetails details;
    private BigDecimal qqb;
    /**
     * 创建用户详情包装
     *
     * @param id      用户编号
     * @param details 详情
     */
    public SecurityUser(long id, UserDetails details,String phone,BigDecimal qqb) {
        this.id = id;
        this.details = details;
        this.phone = phone;
        this.qqb = qqb;
    }

    /**
     * 获取用户编号
     *
     * @return 用户编号
     */
    public long getId() {
        return id;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return details.getAuthorities();
    }

    @Override
    public String getPassword() {
        return details.getPassword();
    }

    @Override
    public String getUsername() {
        return details.getUsername();
    }

    @Override
    public boolean isAccountNonExpired() {
        return details.isAccountNonExpired();
    }

    @Override
    public boolean isAccountNonLocked() {
        return details.isAccountNonLocked();
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return details.isCredentialsNonExpired();
    }

    @Override
    public boolean isEnabled() {
        return details.isEnabled();
    }

    @Override
    public int hashCode() {
        return Long.hashCode(id);
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null || getClass() != obj.getClass()) {
            return false;
        }
        SecurityUser other = (SecurityUser) obj;
        return id == other.getId();
    }

    @Override
    public String toString() {
        return "User:" + id;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public UserDetails getDetails() {
        return details;
    }

    public BigDecimal getQqb() {
        return qqb;
    }
}
